import router from '@/router'
import {post} from '@/util/request'

export default {
	namespace:'rankGroup',
	namespaced:true,
	state:{
		driverLoading:false,
		teamLoading:false,
		driverPagedata:{},
		teamPagedata:{},
		teamCurrent:null,
	},
	mutations:{
		changeDriverLoading(state,v){
			state.isLoading = v;
		},
		changeTeamLoading(state,v){
			state.isLoading = v;
		},
		changeDriverPagedata(state,v){
			state.driverPagedata = v;
		},
		changeTeamPagedata(state,v){
			state.teamPagedata = v;
		},
		changeTeamcurrent(state,v){
			state.teamCurrent = v;
		}
	},
	actions:{
    async loadDriverList({commit},query){
			commit('changeDriverLoading',true);
			let res = await post('/security/securityRanking/driverAllTeamRank',query);
			commit('changeDriverPagedata',res.data.data);
			commit('changeDriverLoading',false);
		},
		async loadTeamList({commit},query){
			commit('changeTeamLoading',true);
			let res = await post('/security/securityRanking/allTeamRank',query);
			commit('changeTeamPagedata',res.data.data);
			let ces = await post('/security/securityRanking/curTeamRank',query);
			commit('changeTeamcurrent',ces.data.data);
			commit('changeTeamLoading',true);
		}
	},
	subscriptions({dispatch},router){
		//给路由加监听一旦进入module绑定的页面时dispatch初始化action
		router.afterEach((to,from)=>{
			if(to.name === this.namespace){

			}
		})
	}
}
